<?php
namespace app\index\model;

use think\Model;
use app\index\model\Comment;
class Words extends Model
{
	protected $pk = 'id';
	protected $table = 'tb_word';
	//查找文章id
	public function find_id($id)
	{
		return Self::get($id);
	}
	//添加数据
	public function add(array $arr)
	{
		return Self::save($arr);
	}

	//获取文章id 及评论
	public function get_word($id)
	{
		return Self::get($id,'comments');
	}
	//删除
	public function word_delete($id)
	{
		$word = Self::get($id,'comments');
		return $word->together('comments')->delete();
	}

	//文章中添加评论
	public function add_comment($id,$arr)
	{
		$words = new Words;
		$word = Words::get($id);
		$n = $word->comments()->save($arr);
		return $n;
	}

	//文章连接评论模型
	public function comments()
	{
		//连接表的模型名 与连接表的连接id 主键
		return $this->hasMany('Comments','word_id','id');
	}

	
}